package juc.container;

import java.util.Iterator;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * @author fangbin
 * @desc
 * @date 2020/6/20 21:31
 */
public class CopyOnWriteListDemo {

    public static List<String>  list = new CopyOnWriteArrayList<>();
    public static void main(String[] args) {
        list.add("1");
        list.add("2");
        list.add("3");
        list.add("4");
        list.add("5");
        Iterator<String> iterator = list.iterator();
        while (iterator.hasNext()){
            System.out.println(list);
            String value = iterator.next();
            if(value.equals("2")){
                list.remove("5");
            }
            if(value.equals("3")){
                list.add("5 found");
            }
            System.out.println(value);
        }
    }
}
